# tool chain for blueprint
SET(CMAKE_SYSTEM_PROCESSOR "P5p")
SET(QMC_ENV "IBMP5p" CACHE STRING "Setting envirnoments for IBM P5+")

SET(HAVE_MPI 0)
SET(ENABLE_OPENMP 1)
SET(ENABLE_FORTRAN 0)
SET(HAVE_ESSL 1)

#SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)

set(CMAKE_C_COMPILER  /usr/vacpp/bin/xlc_r)
set(CMAKE_CXX_COMPILER /usr/vacpp/bin/xlC_r)
#set(CMAKE_CXX_COMPILER /usr/bin/mpCC_r)
set(CMAKE_Fortran_COMPILER /usr/bin/xlf_r)

#SET(AIX_ARCH_FLAGS "-q64 -qarch=pwr7 -qtune=pwr7 -qcache=auto -qsimd=auto -qaltivec -qsmp=omp -qthreaded")
SET(AIX_ARCH_FLAGS "-q64 -qarch=pwr7 -qtune=pwr7 -qcache=auto -qsimd=auto -qhot=simd -qsmp=omp -qthreaded")
SET(AIX_CXX_COMMON_FLAGS "-qrtti=dyna -qnoeh -qsuppress=1540-1090 -DINLINE0= -DINLINE1= -DDOUBLE_PREC")
#SET(AIX_OPT_FLAGS "-O3 -Q -qmaxmem=-1 -qipa=inline -qinline -qlargepage -qprefetch -Drestrict=__restrict__ -qkeyword=restrict -qunroll=yes")
#SET(AIX_OPT_FLAGS "-O3 -qmaxmem=-1 -qlargepage -qprefetch -Drestrict=__restrict__ -qkeyword=restrict -qunroll=yes")
#SET(AIX_OPT_FLAGS "-O3 -qhot=level=1 -qkeyword=restrict -qmaxmem=-1 -qlargepage -qprefetch=assistthread -qunroll=yes ")
#SET(AIX_OPT_FLAGS "-O3 -qhot -qkeyword=restrict -qmaxmem=-1 -qlargepage -qprefetch=assistthread -qunroll=yes ")
#SET(AIX_OPT_FLAGS "-O3 -qinline -qhot -qkeyword=restrict -qmaxmem=-1 -qlargepage -qunroll=yes -qprefetch")
SET(AIX_OPT_FLAGS "-O3 -qhot -qkeyword=restrict -qmaxmem=-1 -qlargepage -qunroll=yes -qprefetch")
#SET(F_DEFINES "-WF,-P,-DESSL,-DDOUBLE_PREC,-DSTRIDE1 -qfixed=132")
SET(F_DEFINES "-qfixed=132")
SET(AIX_F_FLAGS "-O3 -qmaxmem=-1 -qlargepage -qhot -qunroll=yes")

#SET(AIX_OPT_FLAGS "-g -O3 -qlargepage -qprefetch -qstrict -qhot -qkeyword=restrict")
#SET(AIX_OPT_FLAGS "-g -Q -qmaxmem=-1 -qlargepage -qprefetch -qkeyword=restrict")
#SET(AIX_C_FLAGS "-qlanglvl=stdc99")

######################################################################
#set the CXX flags: arch+common + opt 
######################################################################
SET(CMAKE_CXX_FLAGS "${AIX_ARCH_FLAGS} ${AIX_CXX_COMMON_FLAGS} ${AIX_OPT_FLAGS}")
SET(CMAKE_C_FLAGS "${AIX_ARCH_FLAGS} ${AIX_OPT_FLAGS} ${AIX_C_FLAGS}")
SET(CMAKE_Fortran_FLAGS "${F_DEFINES} ${AIX_ARCH_FLAGS} ${AIX_F_FLAGS}")
SET(CMAKE_Fortran_FLAGS_RELEASE ${CMAKE_Fortran_FLAGS})
SET(MAKE_Fortran_IMPLICIT_LINK_LIBRARIES "xlf90_r")
#SET(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "gfortranbegin;gfortran;...")
#SET(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "...") 

#link_libraries(-lessl -lmass -lmassv -lxlf90_r)
#link_libraries(-lessl -lmass -lmassv -lxlf90_r  -L/usr/lpp/ppe.hpct/lib64 -lmpitrace)
#link_libraries(-lessl -lmass -lmassv -lxlf90_r -L/u02/ncsa04/lib -lmpiP)
link_libraries(-lesslsmp -lmass -lmassv -lxlf90_r)
#link_libraries(-L/opt/apps/ibm/essl/5.1/lib64 -lessl -L/opt/apps/ibm/xlf/13.1/lib64 -lxlf90_r)

SET(CMAKE_SHARED_LIBRARY_CREATE_CXXFLAGS "-G -Wl,-brtl,-bnoipath")  # -shared
SET(CMAKE_SHARED_LIBRARY_LINK_CXXFLAGS "-Wl,-brtl,-bnoipath,-bexpall")  # +s, flag for exe link to use shared lib

SET(CMAKE_CXX_CREATE_STATIC_LIBRARY
    "<CMAKE_AR> -X64 cr <TARGET> <LINK_FLAGS> <OBJECTS> " 
    "<CMAKE_RANLIB> <TARGET> ")

SET(CMAKE_Fortran_COMPILE_OBJECT
    "<CMAKE_Fortran_COMPILER> -o <OBJECT>  <FLAGS> -c <SOURCE>")

